package com.example.wananrdroid.fragment.zhufragment.tixi;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.wananrdroid.R;
import com.example.wananrdroid.XiangmuActivity;
import com.example.wananrdroid.adapter.TreeAdapter;
import com.example.wananrdroid.base.BaseFragment;
import com.example.wananrdroid.bean.TreeBean;
import com.example.wananrdroid.presenter.TreePresenter;
import com.example.wananrdroid.view.TreeView;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import qdx.stickyheaderdecoration.NormalDecoration;

public class TiFragment extends BaseFragment<TreePresenter> implements TreeView {
    @BindView(R.id.ti_re)
    RecyclerView mit_re;
    private ArrayList<TreeBean.DataBean> dataBeans;
    private TreeAdapter treeAdapter;

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        mit_re.setLayoutManager(new LinearLayoutManager(getContext()));
        dataBeans = new ArrayList<>();
        treeAdapter = new TreeAdapter(getContext(), dataBeans);
        NormalDecoration normalDecoration = new NormalDecoration() {
            @Override
            public String getHeaderName(int i) {
                return dataBeans.get(i).getName();
            }
        };
        mit_re.addItemDecoration(normalDecoration);
        mit_re.setAdapter(treeAdapter);
        treeAdapter.setOnContextClickListener(new TreeAdapter.OnContextClickListener() {
            @Override
            public void oncontextclicklistener(View v, int position) {
                /*Intent intent = new Intent(getContext(), XiangmuActivity.class);
                TreeBean.DataBean dataBean = dataBeans.get(position);
                String name = dataBean.getName();
                List<TreeBean.DataBean.ChildrenBean> children = dataBean.getChildren();
                Bundle bundle = new Bundle();
                bundle.putSerializable("children", (Serializable) children);
                intent.putExtras(bundle);
                intent.putExtra("name",name);
                startActivity(intent);*/
            }
        });
    }

    @Override
    protected void initPresenter() {
        mPresenter=new TreePresenter();
        mPresenter.treedata();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_ti;
    }

    @Override
    public void onSuccess(TreeBean treedata) {
        dataBeans.addAll(treedata.getData());
        treeAdapter.notifyDataSetChanged();
    }

    @Override
    public void onFali(String error) {

    }

    @Override
    public void showToast(String str) {

    }
}
